home *** CD-ROM | disk | FTP | other *** search
/ Practical Algorithms for Image Analysis / Practical Algorithms for Image Analysis.iso / TARFILE.GZ / tarfile / ch_6.1 / spp / scan_img.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-09-11  |  1.8 KB  |  87 lines

  1. /* 
  2.  * scan_img.c
  3.  * 
  4.  * Practical Algorithms for Image Analysis
  5.  * 
  6.  * Copyright (c) 1997, 1998, 1999 MLMSoftwareGroup, LLC
  7.  */
  8.  
  9. /*
  10.  * SCAN_IMG.C
  11.  *
  12.  * routine to extract point coordinates from input image array
  13.  *
  14.  */
  15. #include <stdlib.h>
  16. #include <stdio.h>
  17. #include "spp.h"
  18.  
  19. #define    F_TO_INT(x)    ( ((x)-(int)(x)<0.5) ? (int)(x) : (int)(x)+1 )
  20.  
  21. #undef    DEBUG
  22.  
  23.  
  24. /*globals */
  25. extern char **image;            /* input/output image */
  26. extern int left_x, right_x;
  27. extern int i, j;
  28.  
  29. extern int NMAX;
  30.  
  31.  
  32.  
  33.  
  34. /*
  35.  * x_pp()
  36.  *   DESCRIPTION:
  37.  *     scan binary image end extract point object coordinates
  38.  *     note: match_index should be identical to the gray value emplyed in
  39.  *     routine mark_centroid()/ah_aoi.c 
  40.  *   ARGUMENTS:
  41.  *     Cxy: Pix structure to be filled in (Pix *)
  42.  *     n: number of points found (long *)
  43.  *     left_x: leftmost x value (int)
  44.  *     imin: row min (int)
  45.  *     right_x: rightmost x value (int)
  46.  *     imax: row max (int)
  47.  *   RETURN VALUE:
  48.  *     1 if NMAX is not exceeded
  49.  *     0 otherwise
  50.  */
  51.  
  52. int
  53. x_pp (Cxy, n, left_x, imin, right_x, imax)
  54.      struct Pix *Cxy;
  55.      long *n;
  56.      int left_x, imin, right_x, imax;
  57. {
  58.   int ir, jc;
  59.   unsigned char cur_index, match_index;
  60.  
  61.  
  62.   match_index = 255;
  63.   printf (" -- match index: %d\n", match_index);
  64.   printf ("...row:");
  65.   for (ir = imin; ir < imax; ir++) {
  66.     if (ir % 50 == 0)
  67.       printf ("...%3d", ir);
  68.  
  69.     for (jc = left_x; jc < right_x; jc++) {
  70.       if ((cur_index = image[ir][jc]) == match_index) {
  71.         if (*n < NMAX) {
  72.           *n += 1;
  73.           (Cxy + *n - 1)->x = (int) (jc);
  74.           (Cxy + *n - 1)->y = (int) ir;
  75. #ifdef DEBUG
  76.           printf ("\n...jc:%d, x:%d, ir:%d, y:%d, n:%ld\n",
  77.                   jc, (Cxy + *n - 1)->x, ir, (Cxy + *n - 1)->y, *n - 1);
  78. #endif
  79.         }
  80.         else
  81.           return (0);
  82.       }
  83.     }
  84.   }
  85.   return (1);
  86. }
  87.